//
//  WBNaviViewController.swift
//  Weibo
//
//  Created by 李磊 on 2017/6/5.
//  Copyright © 2017年 李磊www. All rights reserved.
//

import UIKit

class WBNaviViewController: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        if childViewControllers.count>0 {
            // 隐藏tabbar
            viewController.hidesBottomBarWhenPushed = true
            
            var title = "返回"
            
            // 判断控制器的类型
            if let vc = viewController as? WBBaseViewController {
                
                if childViewControllers.count == 1 {
                    title = childViewControllers.first?.title ?? "返回"
                }
                
                // 取出navigationItem
                vc.navigationItem.leftBarButtonItem = UIBarButtonItem(title: title, target: self, action: #selector(popToPatent), isBack: true)
            }

        }
        
        
        super.pushViewController(viewController, animated: animated)
    }
    
    func popToPatent()  {
        popToRootViewController(animated: true)
    }
    
    
}
